1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4 using
UnityEngine.UI;
5
6 public
class BossHealth : MonoBehaviour {
7
8     
public int maxHealth;
9     
public Slider health;
10     
public bool invulnerable;
11     
public GameObject explode, coin;
12
13     
void Awake(){
14         InitializeBossVariables ();
15     }
16
17     
// Use this for initialization
18     
void Start () {
19         
20     }
21
22     
void InitializeBossVariables(){
23         health.maxValue = maxHealth;
24         health.
value = maxHealth;
25         invulnerable =
true;
26     }
27
28     
public void Health(int damage){
29         
if (!invulnerable) {
30             
if (!health.gameObject.activeInHierarchy) {
31                 health.gameObject.SetActive (
true);
32             }
33
34             
if (health.value > 0) {
35                 health.
value -= damage;
36             }
37
38             
if (health.value == 0) {
39                 BossDestroyed ();
40             }
41         }
42     }
43
44     
void BossDestroyed(){
45         Destroy (gameObject);
46         GameObject.FindGameObjectWithTag (
"Spawner").transform.GetComponent<EnemySpawner> ().active = true;
47         GameObject.FindGameObjectWithTag (
"Spawner").transform.GetComponent<EnemySpawner> ().isBossReady = false;
48         
if(GameController.instance != null && MusicController.instance != null){
49             
if(GameController.instance.isMusicOn){
50                 MusicController.instance.audioSource.PlayOneShot (MusicController.instance.bossExplode);
51             }
52         }
53         Instantiate (explode, transform.position, Quaternion.identity);
54         
for (int i = 0; i < 5; i++) {
55             Instantiate (coin, transform.position, Quaternion.identity);
56         }
57     }
58
59 }


Use this for initialization



Gõ tìm kiếm nhanh...